namespace Vibstudio.X4NET.Xml.Comparision
{
    internal class HashAlgorithm
    {
        internal ulong Hash { get; private set; }

        internal static ulong GetHash(string data)
        {
            return GetHash(data, 0);
        }

        internal void AddString(string data)
        {
            Hash = GetHash(data, Hash);
        }

        internal void AddInt(int i)
        {
            Hash += (Hash << 11) + (ulong)i;
        }

        internal void AddULong(ulong u)
        {
            Hash += (Hash << 11) + u;
        }

        private static ulong GetHash(string data, ulong hash)
        {
            hash += (hash << 13) + (ulong)data.Length;
            for (int i = 0; i < data.Length; i++)
            {
                hash += (hash << 17) + data[i];
            }
            return hash;
        }
    }
}